<template>
    <div class="chart-wrapper">
        <p class="chart-title">年龄</p>
        <div class="chart-content" ref="dom"></div>
    </div>
</template>

<script>
    export default {
        name: "AgeChart",
        data() {
            return {
                chart: null,
                chartData: []
            }
        },
        mounted() {
        },
        methods: {
            updateChart(data) {
                this.chartData = data;
                let option = this.initOption();
                this.chart = this.$echarts.init(this.$refs.dom);
                this.chart.setOption(option);
            },
            initOption() {
                return {
                    grid: {
                        top: '20px',
                        left: '2%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: this.chartData.map(item => item.label),
                        axisTick: {
                            //坐标轴刻度相关设置。
                            show: false,
                        }
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: this.chartData.map(item => item.value),
                        type: 'line',
                        symbolSize: 8,
                        symbol: 'circle',
                        label: {
                            show: true,
                            color: '#3A69C9',
                            position: 'top'
                        },
                        areaStyle: {
                            color: '#3A69C9'
                        },
                        lineStyle: {
                            color: '#3A69C9',
                            width: 1
                        },
                        itemStyle: {
                            color: '#3A69C9'
                        }
                    }]
                };
            }
        }
    };
</script>

<style scoped lang="scss">
    $h: 25px;
    .chart-wrapper {
        width: 100%;
        height: 100%;

        .chart-title {
            display: flex;
            align-items: center;
            justify-content: flex-start;
            padding-left: 1.5%;
            height: $h;
        }

        .chart-content {
            width: 100%;
            height: calc(100% - #{$h});
        }
    }
</style>
